package cn.iocoder.yudao.module.els.dal.mysql.codeGeneratorSerial;

import java.util.*;

import cn.iocoder.yudao.framework.common.pojo.PageResult;
import cn.iocoder.yudao.framework.mybatis.core.query.LambdaQueryWrapperX;
import cn.iocoder.yudao.framework.mybatis.core.mapper.BaseMapperX;
import cn.iocoder.yudao.module.els.dal.dataobject.codeGeneratorSerial.CodeGeneratorSerialDO;
import org.apache.ibatis.annotations.Mapper;
import cn.iocoder.yudao.module.els.controller.admin.codeGeneratorSerial.vo.*;

/**
 * 编码生成器序列 Mapper
 *
 * @author 吕小文
 */
@Mapper
public interface CodeGeneratorSerialMapper extends BaseMapperX<CodeGeneratorSerialDO> {

    default PageResult<CodeGeneratorSerialDO> selectPage(CodeGeneratorSerialPageReqVO reqVO) {
        return selectPage(reqVO, new LambdaQueryWrapperX<CodeGeneratorSerialDO>()
                .eqIfPresent(CodeGeneratorSerialDO::getSerialKey, reqVO.getSerialKey())
                .eqIfPresent(CodeGeneratorSerialDO::getSerialValue, reqVO.getSerialValue())
                .betweenIfPresent(CodeGeneratorSerialDO::getCreateTime, reqVO.getCreateTime())
                .eqIfPresent(CodeGeneratorSerialDO::getGeneratorId, reqVO.getGeneratorId())
                .orderByDesc(CodeGeneratorSerialDO::getId));
    }

    default CodeGeneratorSerialDO getSerialByKey(Long generatorId,String key){
        LambdaQueryWrapperX<CodeGeneratorSerialDO> queryWrapperX = new LambdaQueryWrapperX<>();
        queryWrapperX.eq(CodeGeneratorSerialDO::getGeneratorId,generatorId);
        queryWrapperX.eq(CodeGeneratorSerialDO::getSerialKey,key);
        queryWrapperX.last("limit 1");
        return selectOne(queryWrapperX);
    }

}